package com.ece.devirtualizus.Dao;

import java.io.File;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SqlLiteUserHelper extends SQLiteOpenHelper {

	Context context;
	private static final String DATABASE_NAME = "user.db";
	private static final int DATABASE_VERSION = 1;

	// TABLE USER: 3 ID IMAGE, USERNAME, MOTTO
	public static final String TABLE_USER = "user";
	public static final String COLUMN_ID = "id";
	public static final String COLUMN_LOGIN = "login";
	public static final String COLUMN_MOTTO = "motto";
	public static final String COLUMN_HEAD_IM_ID = "headImId";
	public static final String COLUMN_BODY_IM_ID = "bodyImId";
	public static final String COLUMN_LEG_IM_ID = "legImId";

	private static final String DATABASE_CREATE_TABLE_USER = "create table IF NOT EXISTS "
			+ TABLE_USER
			+ "("
			+ COLUMN_ID
			+ " integer primary key autoincrement, "
			+ COLUMN_LOGIN
			+ " TEXT not null, "
			+ COLUMN_MOTTO
			+ " TEXT not null, "
			+ COLUMN_HEAD_IM_ID
			+ " TEXT not null, "
			+ COLUMN_BODY_IM_ID
			+ " TEXT not null, " + COLUMN_LEG_IM_ID + " TEXT not null);";

	public SqlLiteUserHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE_TABLE_USER);
		Log.i("DATABASE_CREATE", DATABASE_CREATE_TABLE_USER);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER + ";");
	}

	public void destroyDatabase(SQLiteDatabase db) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER + ";");
		Log.i("onDestroy", "DROP TABLE IF EXISTS " + TABLE_USER + ";");
	}

	public boolean checkDataBase() {
		File dbFile = context
				.getDatabasePath("/data/data/com.ece.devirtualizus/databases/user.db");
		return dbFile.exists();
	}

}
